package controllers

import (
	"github.com/gorilla/websocket"
	"net/http"
	"t11Lib/t11Log"
	"亚太-iot-服务器/biz/wsBroker"
	"亚太-iot-服务器/biz/wxBiz"
)

type WxController struct {
	BaseController
}

var upgrader = websocket.Upgrader{
	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}

func (self *WxController) Ws() {
	tk, err := self.getWxUser()
	if err != nil {
		t11Log.Debuglnf("获取微信用户失败，err = %v", err)
		self.Abort("500")
		return
	}
	conn, oerr := upgrader.Upgrade(self.Ctx.ResponseWriter, self.Ctx.Request, nil)
	if oerr != nil {
		t11Log.Debuglnf("升级ws失败，err = %v", oerr)
		self.Abort("500")
		return
	}
	wsBroker.CreateAndRegisterWsClient(tk, conn, wsBroker.WsHub, wxBiz.HandleWsPkt)
}
